<template>
  <div class="map">
    <nav>
      <div class="left" @click="back">&lt;</div>
    </nav>
    <iframe
      id="mapPage"
      width="100%"
      height="100%"
      frameborder="0"
    src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=D56BZ-GLJEX-H2743-TCRZZ-WPHBE-QQF6L&referer=myapp"

    >
    </iframe>
  </div>
</template>
<script>

</script>
<script>
import eventBus from "./eventbus.js";

export default {
  data() {
    return {};
  },
  mounted() {
    var that = this
    window.addEventListener('message', function(event) {
      // 接收位置信息，用户选择确认位置点后选点组件会触发该事件，回传用户的位置信息
      const loc = event.data;
      if (loc && loc.module === 'locationPicker') {//防止其他应用也会向该页面post信息，需判断module是否为'locationPicker'
        console.log(loc);
         
         that.back(loc)
      }
    }, false)
  },
  methods: {
    back(loc) {
     eventBus.$emit("location", loc);

      this.$router.go(-1); //这什么意思路由返回，你知道带参数返回吗
    },
  },
};
</script>
<style lang="scss" scoped>
.map {
  width: 100vw;
  height: 100vh;
font-size: 35px !important;
  nav {
    position: relative;
    width: 100%;
    height: 45px;
    background-color: black;
    color: white;
    text-align: center;
    line-height: 45px;

    .left {
      float: left;
      margin-left: 10px;
    }
  }
}
</style>